<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Class Search extends CI_Controller {
	function __construct(){
            parent:: __construct();
    }
	
	function index()
	{
		$this->barang();
	}

	public function barang(){
		$term    = $_GET['term'];
		$barang  = $this->mpenjualan->getbarang($term)->result();
		$json    = '[';
		foreach($barang as $row){
			$nama = str_replace( '"', "", $row->nama );
			
			if(strlen($json) > 2)
				$json .= ',';
			$json .= '{"value":"' . $row->prokode . "-" . $nama  . "-" .$row->harga1. "-" .$row->satuan.'","label":"' . $row->prokode . " - " . $nama. '"}'; 	
		}	
		$json .= ']';	
		echo $json;
	}

	function pelanggan(){
		$term    = $_GET['term'];
		$barang  = $this->mpelanggan->getcus($term)->result();
		$json    = '[';
		foreach($barang as $row){
			$nama = str_replace( '"', "", $row->nama );
			
			if(strlen($json) > 2)
				$json .= ',';
			$json .= '{"value":"'.$row->pelanggan_id."-".$nama."-".$row->alamat."-".$row->kota."-".$row->tlp.'","label":"' . $row->pelanggan_id . " - " . $nama. '"}'; 	
		}	
		$json .= ']';	
		echo $json;
	}

	function sales(){
		$term    = $_GET['term'];
		$barang  = $this->msales->getsales($term)->result();
		$json    = '[';
		foreach($barang as $row){
			$nama = str_replace( '"', "", $row->nama );
			
			if(strlen($json) > 2)
				$json .= ',';
			$json .= '{"value":"'.$row->sales_id."-".$nama."-".$row->alamat."-".$row->kota."-".$row->tlp.'","label":"' . $row->sales_id . " - " . $nama. '"}'; 	
		}	
		$json .= ']';	
		echo $json;
	}

	function supplier(){
		$term    = $_GET['term'];
		$barang  = $this->msupplier->getsupplier($term)->result();
		$json    = '[';
		foreach($barang as $row){
			$nama = str_replace( '"', "", $row->nama );
			
			if(strlen($json) > 2)
				$json .= ',';
			$json .= '{"value":"'.$row->kode."-".$nama."-".$row->alamat."-".$row->kota."-".$row->tlp.'","label":"'.$row->kode." - ".$nama.'"}'; 	
		}	
		$json .= ']';	
		echo $json;
	}
}
